#include "line_parser.h"
/*--------------------------------------------------------------------------------*/
LINE_PARSER::LINE_PARSER( const TEXT & model ) : ModelLine( model ), DataTable()
{

}
/*--------------------------------------------------------------------------------*/
LINE_PARSER::~LINE_PARSER()
{

}
/*--------------------------------------------------------------------------------*/
BOOL LINE_PARSER::Parse( const TEXT & line )
{
	BOOL
		quit = false,
		passBlank = true;
	TEXT
		temp;
	UINT
		i=0,
		j=0;

	DataTable.Clear();

	while( !quit )
	{
		if( passBlank && ( line[i] == ' ' || ModelLine[j] == ' ') )
		{
			if( line[i] == ' ' ) i++;
			if( ModelLine[j] == ' ' ) j++;

			if( j + 1 > ModelLine.GetLength() ) return true;
		}
		else
		{

			if( j + 1 > ModelLine.GetLength() ) return true;
			if( i + 1 > line.GetLength() ) return false;

			switch(  ModelLine[j] )
			{
				case '\0':
				{
					return true;
				}
				break;

				case '?':
				{
					DataTable.Add( TEXT( line[i] ) );

					j++;
					i++;
				}
				break;


				case '*':
				{
					temp = "";

					while(line[i] && line[i] != ModelLine[j+1] )
					{
						temp += line[i];
						if( !line[i+1] ) break;
						i++;
					}

					DataTable.Add( temp );
					j++;
				}
				break;

				default:
				{
					if( ModelLine[j] == line[i] && line[i] && ModelLine[j] )
					{
						i++;
						j++;

					}
					else
					{
						return false;
					}
				}
				break;
			}
		}
	}

	return false;
}
/*--------------------------------------------------------------------------------*/
